<template>
	<div class="" style="width: 100%;">
		<head-top></head-top>


		<div class="table_container" :style="'width: 90%;  overflow: hidden;  height:1100px;'">
			<div style="margin: 5px; display: flex;">
				<span style="font-size: 20px;width: 300px;">申购赎回 (产品维度): </span>
				<div>
					<el-button size="mini" type="success" @click="refleash()">刷新</el-button>
					<el-button size="mini" type="primary" @click="addnew_arrange()">新增</el-button>
				</div>

				<span style="font-size: medium; padding: 10px;">产品:</span>
				<el-select v-model="product_choice" size="small" clearable filterable placeholder="请选择"
					@change="changeproduct_choice()">
					<el-option v-for="item in product_options" :key="item.label" :label="item.label"
						:value="item.value">
					</el-option>
				</el-select>

				<span style="font-size: medium; padding: 10px;">日期:</span>
				<el-select v-model="date_choice" size="small" clearable filterable placeholder="请选择"
					@change="changedate_choice()">
					<el-option v-for="item in date_options" :key="item.label" :label="item.label" :value="item.value">
					</el-option>
				</el-select>

				<span style="padding-left:30px;">按完成排序:</span>
				<el-switch style="margin-left: 30px;height: 30px; " v-model="order_flag" active-color="#13ce66"
					inactive-color="#ff4949">
				</el-switch>
				<!-- <div>
					<el-button  style="margin-left: 15px;" size="mini" type="warning" @click="finish_all()">所有已处理</el-button>
					<el-button  style="margin-left: 15px;" size="mini" type="success" @click="finish_today()">当日已处理</el-button>
					<el-button  style="margin-left: 15px;" size="mini" type="primary" @click="unfinish_today()">当日重置</el-button>
				</div> -->
			</div>

			<!-- 
			<div style="margin: 15px 5% 0px ; width: 92%;  overflow: hidden; height='400px'" >
						<el-table ref="singleTable" :data="tongjihuizhong" height="500px" border size='mini' :fit='true' :style="'width:'+(screenWidth*1.0)+'px;'" 
 -->

			<el-table ref="singleTable" :data="arrange_data" height="1200px" max-height="1200px" border size='small'
				:fit='true' :style="'width:'+(screenWidth*1.0)+'px;'" :row-class-name=" tableRowClassNamemoneyout">
				<el-table-column prop="id" label="id" width="50" align></el-table-column>

				<el-table-column prop="kkdate" label="date" width="120" align>
					<template slot-scope="scope">
						<el-input v-if="scope.row['status'].indexOf('完成') == -1" v-model="scope.row['kkdate']"
							size="small" placeholder="" @change=" change_cell($event,scope)" @focus="onFocus(scope)"
							@blur="onBlur(scope)"></el-input>
						<span v-if="scope.row['status'].indexOf('完成') != -1"> {{scope.row['kkdate'] }}</span>
					</template>

				</el-table-column>

				<el-table-column prop="prod_code" label="产品代码" width="140" align>
					<template slot-scope="scope">
						<el-select v-if="scope.row['status'].indexOf('完成') == -1" v-model="scope.row['prod_code']"
							size="small" allow-create clearable filterable style="" placeholder="请选择"
							@change=" change_cell($event,scope)" @focus="onFocus(scope)" @blur="onBlur(scope)">
							<el-option v-for="item in product_options" :key="item.value" :label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
						<span v-if="scope.row['status'].indexOf('完成') != -1"> {{scope.row['prod_code'] }}</span>
					</template>
				</el-table-column>
				<el-table-column prop="product_name" label="product_name" width="100" align>
					<template slot-scope="scope">

						<span> {{scope.row['product_name']}}</span>
					</template>

				</el-table-column>

				<el-table-column prop="trade_type" label="trade_type" width="100" align>
					<template slot-scope="scope">
						<el-select v-if="scope.row['status'].indexOf('完成') == -1" v-model="scope.row['trade_type']"
							size="small" clearable filterable allow-create collapse-tags style="" placeholder="请选择"
							@change=" change_cell($event,scope)" @focus="onFocus(scope)" @blur="onBlur(scope)">
							<el-option v-for="item in direction_options" :key="item.value" :label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
						<span v-if="scope.row['status'].indexOf('完成') != -1"> {{scope.row['trade_type'] }}</span>
					</template>

				</el-table-column>




				<el-table-column prop="chg_amount_netvalue" label="资金" width="120" align>
					<template slot-scope="scope">
						<el-input v-if="scope.row['status'].indexOf('完成') == -1"
							v-model="scope.row['chg_amount_netvalue']" size="small" placeholder=""
							@change=" change_cell($event,scope)" @focus="onFocus(scope)"
							@blur="onBlur(scope)"></el-input>
						<span v-if="scope.row['status'].indexOf('完成') != -1">
							{{scope.row['chg_amount_netvalue'] }}</span>
					</template>

				</el-table-column>
				<el-table-column prop="chg_amount_netvalue" label="检查" width="90" align>
					<template slot-scope="scope">

						<span> {{formatNumber(scope.row['chg_amount_netvalue'])}}万</span>
					</template>

				</el-table-column>
				<!-- <el-table-column prop="total_money" label="占比" width="110" align>
					<template slot-scope="scope">
、
						<span> {{formatNumber((scope.row['chg_amount_netvalue'])/scope.row['total_money'])}}%</span>
					</template>

				</el-table-column> -->


				<el-table-column prop="share" label="份额" width="150" align>
					<template slot-scope="scope">
						<el-input v-if="scope.row['status'].indexOf('完成') == -1" v-model="scope.row['share']"
							size="small" placeholder="" @change=" change_cell($event,scope)" @focus="onFocus(scope)"
							@blur="onBlur(scope)"></el-input>
						<span v-if="scope.row['status'].indexOf('完成') != -1"> {{scope.row['share'] }}</span>
					</template>
				</el-table-column>




				<el-table-column prop="allocate_funds" label="allocate_funds" width="500" align>
					<template slot-scope="scope">
						<el-input :disabled="scope.row['status'].indexOf('完成') != -1" type="textarea"
							v-model="scope.row['allocate_funds']" :autosize="{ minRows: 1, maxRows: 6 }" size="small"
							placeholder="" @change=" change_cell($event,scope)" @focus="onFocus(scope)"
							@blur="onBlur(scope)"></el-input>

						<!-- <span  v-if="scope.row['status'].indexOf('完成') != -1" > {{scope.row['allocate_funds'] }}</span> -->
					</template>


				</el-table-column>
				



				<!-- <el-table-column prop="kkupdatetime" label="更新时间" width="140" align></el-table-column> -->
				<el-table-column prop="status" label="状态" width="120" align>
					<template slot-scope="scope">
						<!-- :disabled="scope.row['status']=='完成' " -->
						<el-select v-model="scope.row['status']" size="small" collapse-tags style="" placeholder="请选择"
							@change=" change_cell($event,scope)" @focus="onFocus(scope)" @blur="onBlur(scope)">
							<el-option v-for="item in status_options" :key="item.value" :label="item.label"
								:value="item.value">
							</el-option>
						</el-select>

					</template>
				</el-table-column>

				

				<el-table-column label="操作" :width='200'>
					<template slot-scope="scope">
						<el-button size="mini" type="danger" @click="handleDelete(scope.$index, scope.row)">删除
						</el-button>
						<el-button size="small" type="warning" :disabled="!auto_assignment_list.includes( scope.row['product_name'])" @click="autofix(scope.$index, scope.row)">自动分配</el-button>
					</template>
				</el-table-column>
				<!-- <el-table-column prop="note" label="备注" width="200" align>
					<template slot-scope="scope">
						<el-input v-if="scope.row['status'].indexOf('完成') == -1" v-model="scope.row['note']"
							size="small" placeholder="" @change=" change_cell($event,scope)" @focus="onFocus(scope)"
							@blur="onBlur(scope)"></el-input>
						<span v-if="scope.row['status'].indexOf('完成') != -1"> {{scope.row['note'] }}</span>
					</template>

				</el-table-column> -->
				<el-table-column prop="asker" label="需求人" width="120" align>
					<template slot-scope="scope">
						<el-select v-show="scope.row['status'].indexOf('完成') == -1" v-model="scope.row['asker']"
							size="small" clearable filterable allow-create collapse-tags style="" placeholder="请选择"
							@change=" change_cell($event,scope,'input')" @focus="onFocus(scope)" @blur="onBlur(scope)">
							<el-option v-for="item in worker_list1" :key="item.value" :label="item.label"
								:value="item.value">
							</el-option>
						</el-select>
						<span v-show="scope.row['status'].indexOf('完成') != -1"> {{scope.row['asker'] }}</span>
					</template>
				
				</el-table-column>
				<el-table-column prop="releated_purchase_id" label="资金到账关联申购id" width="320" align>
					<template slot-scope="scope">
						<!-- :disabled="scope.row['status']=='完成' " -->
						<el-select v-model="scope.row['releated_purchase_id']"
							:disabled="(scope.row['trade_type']!='资金到账' )||(scope.row['status'].indexOf('完成') != -1) "
							size="small" collapse-tags style="" placeholder="请选择" clearable=""
							@change=" change_cell($event,scope)" @focus="onFocus(scope)" @blur="onBlur(scope)">
							<el-option v-for="item in releated_purchase_id_options" :key="item.value"
								:label="item.label" :value="item.value">
							</el-option>
						</el-select>
				
					</template>
				</el-table-column>
				
				<el-table-column prop="kkupdatetime" label="updatetime" width="200" align></el-table-column>
			</el-table>

		</div>

	</div>
</template>

<script>
	import headTop from '@/components/headTop'
	export default {
		data() {
			return {
				checkflag: false,
				core_pos: [],
				pos_index_item: '',
				product_choice: "",
				product_options: [],
				target_pos_index_options: [],
				date_choice: "",
				date_options: [],
				auto_assignment_list:[],
				tableData: [],
				currentRow: null,
				inputdatenum: 22,
				releated_purchase_id_options: [],

				count: 0,
				exchange_detail: [],

				fix_account: {},
				visible: false,
				visible2: false,
				order_flag: true,

				screenWidth: document.body.clientWidth, // 屏幕尺寸
				screenHeight: document.body.clientHeight, // 屏幕尺寸
				purchase_id: "",
				arrange_data: [],
				config_account_list: [],
				worker_list1: [{
						value: '郭健',
						label: '郭健'
					},

					{
						value: '希睿',
						label: '希睿'
					},
					{
						value: 'richard',
						label: 'richard'
					},
					{
						value: 'Yukki',
						label: 'Yukki'
					},
				],

				status_options: [{
						value: '待处理',
						label: '待处理'
					},

					{
						value: '准备',
						label: '准备'
					},
					{
						value: '完成',
						label: '完成'
					},
					{
						value: '分配完成',
						label: '分配完成'
					},
				],
				yseno_options: [{
						value: 'yes',
						label: 'yes'
					},
					{
						value: 'no',
						label: 'no'
					},


				],

				direction_options: [{
						value: '申购',
						label: '申购'
					},
					{
						value: '赎回',
						label: '赎回'
					},

					{
						value: '资金到账',
						label: '资金到账'
					},

					{
						value: '移仓',
						label: '移仓'
					},



				],


			}
		},
		components: {
			headTop,
		},



		activated() {

			// console.log("当前登入用户", this.$store.state.adminInfo.name);
			//    if (this.tradesysPermission_list.indexOf (this.$store.state.adminInfo.permission) ==-1) {
			// 	console.log(this.$store.state.adminInfo.name,"未登入")
			// 	this.$message({type: 'error',	message: '没有权限',});
			// 	this.$router.push({
			// 		path: `/manage`
			// 	})
			// }
		},
		mounted() {
			this.get_exchange_arrange()
		},
		created() {
			// this.get_tradesys_account()
			this.get_tradesys_account()
			this.get_tradesys_product()
			this.get_date_last()
		},
		computed: {

		},

		methods: {
			formattedText() {
				// 使用 <br> 标签替换 \n  
				return this.rawText.replace(/\n/g, '<br>');
			},

			formatNumber(num) {
				// 检查输入是否为数字

				if (typeof num !== 'number' || isNaN(num)) {
					return '输入无效';
				}
				num = num / 10000
				// 判断数字是否为整数（使用取余运算）  
				if (Number.isInteger(num) || (num % 1 === 0)) {
					// 如果是整数，直接返回整数部分（转为字符串以去除科学计数法表示）  
					return num.toString();
				} else {
					// 如果不是整数，保留两位小数并返回字符串形式  
					return num.toFixed(2);
				}
			},
			onFocus(scope) {
				// console.log(scope.row.id, 'onFocus')
				this.$axios.post(this.lpapi2, "form=onfocus&summary_id=" + scope.row.id + "&writer=" + this.$store.state.adminInfo.name).then(
				response => {
					if (response.status = 200) {
						// console.log(response.data);
						if (response.data!='success'){
							this.$message({
								message: response.data,
								type: 'warning',
								duration: 0,
								showClose: true 
							});
						}
					} 
				
				})
			},
			onBlur(scope) {
				// console.log(scope.row.id, 'onBlur')

				this.$axios.post(this.lpapi2, "form=onblur&summary_id=" + scope.row.id + "&writer=" + this.$store.state.adminInfo.name).then(
				response => {
					if (response.status = 200) {
						// console.log(response.data);
						if (response.data!='success'){
							this.$message({
								message: response.data,
								type: 'warning',
								duration: 0,
								showClose: true 
							});
						}
					} 

				})

			},
			changedate_choice() {

				this.get_exchange_arrange()
			},

			changeproduct_choice() {
				this.get_exchange_arrange()
			},
			async change_cell($event, scope) {
				console.log(scope.$index)
				var that = this
				console.log(scope)
				var arrange_data_item = this.arrange_data[scope.$index]
				let product_str = ''
				if (scope.column['label'] == '产品代码' || scope.column['label'] == '资金') {
					// let add_money=arrange_data_item['chg_amount_netvalue']
					let add_money = 0
					let total_money = 0

					for (var i = 0; i < that.config_account_list.length; i++) {

						if (that.config_account_list[i]['prod_code'] == this.arrange_data[scope.$index]['prod_code']) {
							if (that.config_account_list[i]['account_type'] != 'index_future') {
								arrange_data_item['product_name'] = that.config_account_list[i]['product_name']
								this.arrange_data[scope.$index]['product_name'] = that.config_account_list[i][
									'product_name'
								]
								product_str += that.config_account_list[i]['program_code'] + '[ ' + add_money +
									' ]元 ' + that.config_account_list[i]['product_strategy'] + '目前' +
									that.config_account_list[i]['total_asset'] + '万\n'
								add_money = 0

								total_money += that.config_account_list[i]['total_asset']
							};

						}

					}
					this.arrange_data[scope.$index]['total_money'] = total_money
					arrange_data_item['total_money'] = total_money
					this.arrange_data[scope.$index]['allocate_funds'] = product_str
					arrange_data_item['allocate_funds'] = product_str
					this.get_releated_purchase_id_options(arrange_data_item['prod_code'])

				}
				if (scope.column['label'] == '份额') {

					let dwjz = await this.get_fund_data(arrange_data_item['product_name'])
					let mon1 = parseFloat(dwjz) * parseFloat(arrange_data_item['share'])
					let mon2 = Math.round(mon1 / 10000) * 10000

					arrange_data_item['chg_amount_netvalue'] = mon2
					this.arrange_data[scope.$index]['chg_amount_netvalue'] = mon2
				}
				if (arrange_data_item['trade_type'] == '资金到账' || arrange_data_item['trade_type'] == '申购') {
					arrange_data_item['share'] = 0
					this.arrange_data[scope.$index]['share'] = 0
				}
				if (!isNaN(parseFloat(arrange_data_item['chg_amount_netvalue']))) {
					console.log(parseFloat(arrange_data_item['chg_amount_netvalue']))



					if (arrange_data_item['trade_type'] == '申购' && parseFloat(arrange_data_item[
						'chg_amount_netvalue']) <= 0) {

						this.$message({
							message: '申购资金 必须大于0',
							type: 'warning'
						});
						return
					}
					if (arrange_data_item['trade_type'] == '资金到账' && parseFloat(arrange_data_item[
							'chg_amount_netvalue']) <= 0) {

						this.$message({
							message: '到账资金 必须大于0',
							type: 'warning'
						});
						return
					}
					if (arrange_data_item['trade_type'] == '赎回' && parseFloat(arrange_data_item[
						'chg_amount_netvalue']) > 0) {
						this.$message({
							message: '赎回资金 必须小于0',
							type: 'warning'
						});
						return
					}


				}

				let sql2 = "UPDATE `prod_purchase_redeem_summary` SET `trade_type` = '" + arrange_data_item[
						'trade_type'] + "',   \
				   `date` = '" + arrange_data_item['kkdate'] + "', `prod_code` = '" + arrange_data_item['prod_code'] + "',   \
					`chg_amount_netvalue` = '" + arrange_data_item['chg_amount_netvalue'] + "', `product_name` = '" +
					arrange_data_item['product_name'] + "',   \
					`allocate_funds` = '" + arrange_data_item['allocate_funds'] + "', `share` = '" + arrange_data_item['share'] + "',\
					`note` = '" + arrange_data_item['note'] + "', `asker` = '" + arrange_data_item['asker'] + "', `status` = '" +
					arrange_data_item['status'] + "'\
					WHERE `id` = " + arrange_data_item['id'] + " ; "



				let sql22 = "INSERT INTO `prod_purchase_redeem_summary_history`(`id`,`product`,`log`,`worker`,`label`, `updatetime`) \
				 VALUES ('" + arrange_data_item['id'] + "','" + arrange_data_item['product_name'] + "','" + arrange_data_item[scope
						.column['property']] + "','" +
					this.$store.state.adminInfo.name + "','" + scope.column['label'] + "',CURRENT_TIMESTAMP);"


				that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql22).then(response => {
					console.log(response, 'do_sql');
				})


				if (scope.column['label'] == 'allocate_funds') {
					arrange_data_item['asker'] = this.$store.state.adminInfo.name
					this.arrange_data[scope.$index]['asker'] = this.$store.state.adminInfo.name
				}








				let user_open_id = 'all'
				if (arrange_data_item['status'] == '待处理' && scope.column['label'] == '状态') {
					let msg =
						`编号:${arrange_data_item['id']} 产品:${arrange_data_item['product_name']} ${arrange_data_item['trade_type']} ${arrange_data_item['chg_amount_netvalue']}元 待分配`
					that.$axios.post(that.lpapi2, "form=send_feishu_msg&user=" + user_open_id + "&msg=" + msg +
						"&chart_id=oc_1bffba92be273dc5cc087d7162bd0ef6").then(response => {
						console.log(response, 'send_msg');
						if (response.status = 200) {} else {
							console.log(response.data.statusCode);
						}

					})
				}


				let user_open_id1 = 'all'
				if (arrange_data_item['status'] == '分配完成' && scope.column['label'] == '状态') {

					const inputString = arrange_data_item['allocate_funds']
					const parts = inputString.split('\n');


					let filteredParts = [];
					let total_money = 0
					parts.forEach(part => {
						const regex = /\[\s*(-?\d+)\s*\]/;
						const match = part.match(regex);
						if (match) {
							// match[1] 包含括号中的数字，因为 match[0] 是整个匹配的字符串（包括括号）  
							const numberInsideBrackets = parseInt(match[1], 10);
							console.log(numberInsideBrackets); // 输出: 133  

							if (numberInsideBrackets != 0) {
								const celue = part.split('元')[1];
								const celue1 = celue.split('目前')[0];
								const celue2 = celue1 + '->' + String(numberInsideBrackets / 10000) + '万元'
								filteredParts.push(celue2);
								total_money += numberInsideBrackets
							}

						}
					});
					if (total_money != arrange_data_item['chg_amount_netvalue']) {
						this.$message({
							message: '资金不匹配',
							type: 'error'
						});
						arrange_data_item['status'] = '准备'
						this.arrange_data[scope.$index]['status'] = '准备'

						// this.get_exchange_arrange();  
						return
					}

					const resultString = filteredParts.join(' ');

					let msg1 =
						`编号:${arrange_data_item['id']} 产品:${arrange_data_item['product_name']} ${arrange_data_item['trade_type']} ${arrange_data_item['chg_amount_netvalue']}元 ${arrange_data_item['asker']} 分配如下： ${resultString} `
					console.log(msg1);

					that.$axios.post(that.lpapi2, "form=send_feishu_msg&user=" + user_open_id + "&msg=" + msg1 +
						"&chart_id=oc_1bffba92be273dc5cc087d7162bd0ef6").then(response => {
						console.log(response, 'send_msg');
						if (response.status = 200) {} else {
							console.log(response.data.statusCode);
						}

					})
				}

				if (arrange_data_item['status'] == '完成' && scope.column['label'] == '状态') {


					const data = {
						module_name: "yxk_tool.product_trade",
						function_name: "update_purredeem",
						args: [arrange_data_item['id']],
						kwargs: {}
					};

					that.$axios.post(that.lpcallfunction, data).then(response => {
						console.log(response, 'update_purredeem');
						if (response.status = 200) {
							if (response.data[0].code == 'error') {
								this.$message({
									message: response.data[0].message,
									type: 'error'
								});
								arrange_data_item['status'] = '准备'
								this.arrange_data[scope.$index]['status'] = '准备'

								// this.get_exchange_arrange();  
								return
							}

							that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
								console.log(response, 'do_sql');
								if (response.status = 200) {
									this.$message({
										message: '更新',
										type: 'success'
									});
									this.arrange_data[scope.$index] = arrange_data_item
									// this.get_exchange_arrange()
								} else {
									return
									console.log(response.data.statusCode);
								}
							})


						} else {
							console.log(response.data.statusCode);
						}

					})

				} else {
					that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
						console.log(response, 'do_sql');
						if (response.status = 200) {
							this.$message({
								message: '更新',
								type: 'success'
							});
							this.arrange_data[scope.$index] = arrange_data_item
							// this.get_exchange_arrange()
						} else {
							return
							console.log(response.data.statusCode);
						}
					})

				}



			},
			autofix(index, row) {
				console.log(row['id'])
				var that = this;
				that.$axios.post(that.lpapi1, "form=fix_prod_summary_allocate_funds&rowid=" + row['id']).then(response => {
					if (response.status = 200) {
						this.$message({
							message: '更新完成',
							type: 'success'
						});
						this.get_exchange_arrange()
					} else {
						console.log(response.data.statusCode);
					}
				})
			},


			handleDelete(index, row) {
				console.log(row)
				var that = this;
				let sql22 = "INSERT INTO `prod_purchase_redeem_summary_history`(`id`,`product`,`log`,`worker`,`label`, `updatetime`) \
				 VALUES ('" + row['id'] + "','" + row['product_name'] + "','删除记录','" + this.$store.state.adminInfo.name +
					"','',CURRENT_TIMESTAMP);"


				that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql22).then(response => {
					console.log(response, 'do_sql');
				})


				console.log("row", row['kkdate'], "program_code", row['program_code'])
				this.purchase_id = row['id']


				// this.exchange_arrange=row


				this.$confirm('此操作将永久修改数据, 是否继续?', '提示', {
					confirmButtonText: '确定',
					cancelButtonText: '取消',
					inputType: 'password',
					type: 'warning'
				}).then(() => {


					let sql2 = "delete from `prod_purchase_redeem_summary`  WHERE `id`='" + this.purchase_id +
						"'   ;"

					that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
						console.log(response, 'do_sql');
						if (response.status = 200) {
							this.$message({
								message: '删除完成',
								type: 'success'
							});
							this.get_exchange_arrange()
						} else {
							return
							console.log(response.data.statusCode);
						}
					})
					let sql3 = "delete from `LP_tradesys_money`  WHERE `summary_id`='" + this.purchase_id + "'   ;"

					that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql3).then(response => {
						console.log(response, 'do_sql');
						if (response.status = 200) {} else {
							return
						}
					})
					let sql4 = "delete from `prod_purchase_redeem`  WHERE `summary_id`='" + this.purchase_id +
						"'   ;"

					that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql4).then(response => {
						console.log(response, 'do_sql');
						if (response.status = 200) {

						} else {
							return
						}
					})

				}).catch(() => {
					this.$message({
						type: 'info',
						message: '取消删除'
					});
				});
			},





			refleash() {
				this.get_exchange_arrange()
			},
			addnew_arrange() {
				var that = this;
				var date = new Date();
				var seperator1 = "-";
				var year = date.getFullYear();
				var month = date.getMonth() + 1;
				var strDate = date.getDate();
				if (month >= 1 && month <= 9) {
					month = "0" + month;
				}
				if (strDate >= 0 && strDate <= 9) {
					strDate = "0" + strDate;
				}

				var currentdate = year + seperator1 + month + seperator1 + strDate;
				let sql2 = "INSERT INTO `prod_purchase_redeem_summary`(`date`,`status`,`updatetime`,`trade_type`,`chg_amount_netvalue`,`share`,`note`,`prod_code`,`asker`) \
				 VALUES ('" + currentdate + "','准备',CURRENT_TIMESTAMP,'申购','0','0','','','');"
				that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
					console.log(response, 'do_sql');
					if (response.status = 200) {
						this.$message({
							message: '新增完成',
							type: 'success'
						});
						this.get_exchange_arrange()
					} else {
						return
						console.log(response.data.statusCode);
					}
				})

			},
			get_releated_purchase_id_options(product_id) {
				var that = this;


				let sql =
					" select *,date_format(date,'%Y-%m-%d') as kkdate from `prod_purchase_redeem_summary`  where trade_type='申购' and prod_code='" +
					product_id + "' and date > NOW() - INTERVAL 5 DAY;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
					console.log(response, 'data_tradesys_account');
					if (response.status = 200) {
						that.releated_purchase_id_options = []
						//for (var i = 0; i < response.data.length; i++) {
						for (var i = response.data.length - 1; i >= 0; i--) {
							let char = {
								value: response.data[i]['id'],
								label: response.data[i]['id'] + '/' + response.data[i]['prod_code'] + '/' +
									response.data[i]['kkdate'] + '/' + response.data[i][
									'chg_amount_netvalue'] + '元',
							};
							that.releated_purchase_id_options.push(char);
						}
					} else {
						console.log(response.data.statusCode);
					}
				})

			},
			get_date_last() {
				var that = this;


				let sql =
					" select date_format(date,'%Y-%m-%d') as kkdate ,date from `prod_purchase_redeem_summary`  GROUP BY date;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
					console.log(response, 'data_tradesys_account');
					if (response.status = 200) {
						that.date_options = []
						//for (var i = 0; i < response.data.length; i++) {
						for (var i = response.data.length - 1; i >= 0; i--) {
							let char = {
								value: response.data[i]['kkdate'],
								label: response.data[i]['kkdate'],
							};
							that.date_options.push(char);
						}
					} else {
						console.log(response.data.statusCode);
					}
				})

			},
			finish_all() {

				var that = this;


				let sql2 = "update `prod_purchase_redeem_summary` set status='完成' "
				that.$axios.post(that.lpapi2, "form=do_sql&sql=" + sql2).then(response => {
					console.log(response, 'do_sql');
					if (response.status = 200) {
						this.$message({
							message: '更新完成',
							type: 'success'
						});
						this.get_exchange_arrange()
					} else {
						return
						console.log(response.data.statusCode);
					}
				})

			},

			get_tradesys_product() {
				var that = this;
				// console.log(that.lpapi2)

				let sql = "select distinct product_nick_name,product_name,assignment from config_product where in_use='yes' ;"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {

					console.log(response, 'config_product')
					that.auto_assignment_list = []
					if (response.status = 200) {
						that.product_options = []
						for (var i = 0; i < response.data.length; i++) {
							let char = {
								value: response.data[i]['product_nick_name'],
								// label: response.data[i]['account'],
								label: response.data[i]['product_nick_name'],

							};

							that.product_options.push(char);
							if(response.data[i]['assignment']=='auto'){
								that.auto_assignment_list.push(response.data[i]['product_name'])
								
							}
							
						}
					console.log('auto_assignment_list',that.auto_assignment_list);
					} else {
						console.log(response.data.statusCode);
					}
				})


			},
			get_fund_data(product_name) {
				var that = this;
				return new Promise((resolve, reject) => {
					let sql = "select date,dwjz_sum from LP_fund_value_day where product_name='" + product_name +
						"' and dwjz_sum>0  order by date desc limit 1 ;"
					// 注意：这里应该使用参数化查询来避免SQL注入，但具体实现取决于您的后端API如何支持参数化  
					// 假设您的后端API不支持参数化，下面的代码仍然有SQL注入的风险  
					// 在实际应用中，您应该找到一种方法来安全地传递product_name  

					that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {
						if (response.status === 200 && response.data && response.data.length > 0) {
							resolve(response.data[0]['dwjz_sum']);
						} else {
							console.error('Error fetching fund data:', response.data || response
								.statusText);
							reject(new Error('Failed to fetch fund data'));
						}
					}).catch(error => {
						console.error('Axios error:', error);
						reject(error);
					});
				});
			},

			get_tradesys_account() {
				var that = this;
				// console.log(that.lpapi2)
				let sql =
					"SELECT   config.account,  config.program_code, config.product_strategy,  \
config.prod_code,  config.product_name,  config.account_type,   ROUND(qry.total_asset / 10000) AS total_asset  FROM \
config_account config  LEFT JOIN   (SELECT   total_asset,   account   FROM   LP_account_trade_qry  \
WHERE   (account, datetime) IN (  SELECT   account,   MAX(datetime)  FROM   LP_account_trade_qry  \
WHERE   total_asset > 0   AND date >= CURDATE() - INTERVAL 31 DAY  GROUP BY  account  )  ) qry  \
ON   qry.account = config.account  WHERE  config.use_flag = 'yes' and  config.account_type!='sig_server' order by config.product_strategy"
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {

					// console.log(response, 'config_product')
					this.config_account_list = []
					if (response.status = 200) {
						this.config_account_list = response.data

					} else {
						console.log(response.data.statusCode);
					}
				})


			},
			get_exchange_arrange() {
				var that = this;
				console.log(that.lpapi2)
				// let flag1='入金'
				// if (this.inoutflag){
				// 	 flag1='出金'
				// }else{
				// 	 flag1='入金'

				// }
				let order_str = ""
				if (this.order_flag) {

					order_str = "CASE WHEN status = '完成' THEN 1  ELSE 0    END ASC,"
				} else {

					order_str = "date desc,product_name,"
				}
				let sql =
					"select * ,date_format(date,'%Y-%m-%d') as kkdate,date_format(updatetime,'%Y-%m-%d  %H:%i:%s') as kkupdatetime \
					from `prod_purchase_redeem_summary`   ORDER BY " + order_str + "   id,kkupdatetime desc  limit 100;"

				if (this.product_choice != "" && this.date_choice != "") {
					sql =
						"select * ,date_format(date,'%Y-%m-%d') as kkdate,date_format(updatetime,'%Y-%m-%d  %H:%i:%s') as kkupdatetime \
					from `prod_purchase_redeem_summary` where prod_code='" + this.product_choice + "' and  date='" + this
						.date_choice +
						"' ORDER BY  " + order_str + " id,kkupdatetime desc  limit 100;"
				} else if (this.product_choice != "") {
					sql =
						"select * ,date_format(date,'%Y-%m-%d') as kkdate,date_format(updatetime,'%Y-%m-%d  %H:%i:%s') as kkupdatetime \
					from `prod_purchase_redeem_summary` where   prod_code='" + this.product_choice +
						"'  ORDER BY  " + order_str + " id,kkupdatetime desc  limit 100;"
				} else if (this.date_choice != "") {
					sql = "select * ,date_format(date,'%Y-%m-%d') as kkdate,date_format(updatetime,'%Y-%m-%d  %H:%i:%s') as kkupdatetime \
					from `prod_purchase_redeem_summary` where  date='" + this.date_choice + "'  ORDER BY  " + order_str +
						" id,kkupdatetime desc  limit 100;"
				}

				that.arrange_data = []
				that.$axios.post(that.lpapi2, "form=get_data&sql=" + sql).then(response => {

					console.log(response.data[0], 'prod_purchase_redeem_summary')

					if (response.status = 200) {
						if (response.data[0].hasOwnProperty('message')) {
							that.arrange_data = []
						} else {
							that.arrange_data = response.data;
						}
						// that.arrange_data = response.data;
					} else {
						console.log(response.data.statusCode);
					}
				})


			},




			tableRowClassNamemoneyout({
				row,
				rowIndex
			}) {

				if (this.arrange_data[rowIndex]['trade_type'] == '申购' && this.arrange_data[rowIndex]['status'] == '准备') {
					return 'bacorange';
				}
				if (this.arrange_data[rowIndex]['trade_type'] == '赎回' && this.arrange_data[rowIndex]['status'] == '准备') {
					return 'DodgerBlue';
				}
				if (this.arrange_data[rowIndex]['trade_type'] == '资金到账' && this.arrange_data[rowIndex]['status'] == '准备') {
					return 'LimeGreen';
				}
				if (this.arrange_data[rowIndex]['status'] == '待处理') {
					return 'bacRed';
				}
				return '';
			}

		},
	}
</script>

<style>
	.my-table {

		/* 滚动条高度调整 */
		.el-table--scrollable-x .el-table__body-wrapper::-webkit-scrollbar {
			height: 12px;
		}

		/* 解决固定列遮挡滚动条的问题 */
		.el-table__fixed,
		.el-table__fixed-left,
		.el-table__fixed-right {
			pointer-events: none;
		}

		.el-table__fixed td,
		.el-table__fixed-left td,
		.el-table__fixed-right td {
			pointer-events: auto;
		}
	}

	.el-table .bacorange {
		background: orange;
	}
	.el-table .bacRed {
		background: LightCoral;
	}
	.el-table .success-row {
		background: grey;
		color: white;
	}

	.table_container {
		margin: 20px 5%;
		/* background-color: #0000FF; */
	}

	.el-table .grey {
		background: Silver;
	}

	.el-table .DarkGray {
		background: DarkGray;
	}

	.el-table .LightCoral {
		background: LightCoral;
		color: white;
	}

	.el-table .LimeGreen {
		background: LimeGreen;
	}

	.el-table .green {
		background: green;
	}

	.el-table .LightSlateGray {
		background: LightSlateGray;
	}

	.el-table .red {
		background: red;
		color: white;
	}

	.el-table .orange {
		background: NavajoWhite;
		color: black;
	}

	.el-table .blue {
		background: blue;
	}

	.el-table .purple {
		background: Violet;
		color: black;
	}

	.el-table .LightSteelBlue {
		background: LightSteelBlue;
	}

	.el-table .Goldenrod {
		background: Goldenrod;
	}

	.el-table .xingmu {
		background: Goldenrod;
		color: red;
		font-weight: bold;

	}


	.el-table .black {
		background: black;
		color: white;
	}

	.el-table .green {
		background: green;
		color: white;
	}

	.el-table .CornflowerBlue {
		background: CornflowerBlue;
		color: white;
	}

	.el-table .DodgerBlue {
		background: DodgerBlue;
	}
</style>